package com.errands.cn.services;

import com.errands.cn.entity.OrderReceiving;
import com.errands.cn.mapper.OrderReceivingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class OrderRecivingService {

    @Autowired
    private OrderReceivingMapper receivingMapper;

    public boolean save(OrderReceiving receiving){
        try {
            receivingMapper.insert(receiving);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    public boolean update(OrderReceiving receiving){
        try {
            receivingMapper.updateByPrimaryKeySelective(receiving);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    public boolean deleteRecivedOrder(Integer oId){
        try {
            receivingMapper.deleteByPrimaryKey(oId);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    public OrderReceiving getOrderReceingById(Integer id){
       return receivingMapper.selectByPrimaryKey(id);
    }

    public List<OrderReceiving> getOrderReceving(Integer state,Integer sendUid){
        return receivingMapper.selectByState(state,sendUid);
    }

    public OrderReceiving getOrderReceingByoId(String oId){
        return receivingMapper.selectByoId(oId);
    }
}
